/*
 * Author: Thomas
 * 
 */

cmt.datatables.createColumnDefByRenderingColumnAsLinkToId = function (idColumn, linkColumn, baseUrl) {
    function renderFunction(data, type, row) {
        var detailUrl = baseUrl + row[idColumn];
        var display = cmt.asLinkTag(data, detailUrl);
        return display;
    }
    
    if (idColumn !== linkColumn) {
        return [
            {"targets": [linkColumn], // link to detail view
                "render": renderFunction
            },
            {"targets": [idColumn], // id invisible
                "visible": false}
        ];
    } else {
        return [
            {"targets": [linkColumn], // link to detail view
                "render": renderFunction
            }
        ];
    }
};

/**
 * Creates a link tag.
 * @param {type} data - content (display text)
 * @param {type} link - location
 * @returns {String}
 */
cmt.asLinkTag = function (data, link) {
    return "<a href='" + link + "'>" + data + "</a>";
};

cmt.submitParentFormOf = function (element) {
    $(element).closest("form").submit();
};

cmt.submitFormWithName = function (name) {
    $("form[name='" + name + "']").submit();
};